home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994…tember: Reference Library / Dev.CD Sep 94.toast / Technical Documentation / PCI Information / PCI Developer’s Kit (disk) / PCI Testing / Hardware.c next >
Encoding:
C/C++ Source or Header  |  1994-06-27  |  6.6 KB  |  251 lines  |  [TEXT/MPS ]

  1. /*
  2. *
  3. * © Copyright 1994, Apple Computer, Inc.
  4. *
  5. * by Rob Glanville
  6. *
  7. * 31 Mar 94
  8. *
  9. * Hardware.c - Hardware interface for PCI compliance tests
  10. *
  11. */
  12.  
  13. #define UInt8        unsigned char
  14. #define UInt16        unsigned short
  15. #define UInt32        unsigned long
  16. #define    PInt8        *(UInt8 *)            /* Used for physical address casting */
  17. #define    PInt16        *(UInt16 *)            /* Used for physical address casting */
  18. #define    PInt32        *(UInt32 *)            /* Used for physical address casting */
  19. #define True        0xffffffff
  20. #define False        0x00000000
  21. #define    Null        False                /* Nothing but trouble */
  22. #define CR            0x0d
  23. #define LF            0x0a
  24.  
  25. extern UInt8  Int8Read  (UInt32);
  26. extern UInt16 Int16Read (UInt32);
  27. extern UInt32 Int32Read (UInt32);
  28. extern void   Int8Write (UInt32,UInt8);
  29. extern void   Int16Write(UInt32,UInt16);
  30. extern void   Int32Write(UInt32,UInt32);
  31. extern void   printstr(const char *);
  32. extern void   outchar(UInt8);
  33. extern void   byteout(UInt8);
  34. extern void   wordout(UInt16);
  35. extern void   longout(UInt32);
  36. extern void   crlf();
  37. extern void      LineIn();
  38. extern void   Upper(UInt8 *);
  39. extern void   ScanDelimiters();
  40. extern void   getarg();
  41. extern UInt16 GetValue();
  42. extern UInt16 PeekMemory();
  43. extern UInt16 DisplayMemory();
  44. extern UInt16 FillMemory();
  45. extern void   SyntaxError();
  46.  
  47. extern UInt8 CommandLine[256];    /* Input buffer                                */
  48. extern UInt8 delimiter;            /* Delimiter between arguments                */
  49. extern UInt8 AsciiBuf[19];        /* A buffer for output                        */
  50. extern UInt8 Argument[0x80];    /* The arguments go here one by one            */
  51. extern UInt8 TabSize;            /* Size of tab stops                        */
  52.  
  53. extern UInt16 ArgSize;            /* Argument size                            */
  54. extern UInt16 CPointer;            /* Command pointer                            */
  55.  
  56. extern UInt32 CommandIndex;        /* The index into command buffer            */
  57. extern UInt32 number;            /* A place for all numbers input            */
  58. extern UInt32 BufPtr;            /* Alias buffer pointer for unions            */
  59. extern UInt32 Base;                /* Base address for all accesses            */
  60. extern UInt32 Offset;            /* Offset address for some accesses            */
  61. extern UInt32 accessMethod;        /* Type of hardware access                    */
  62.  
  63. #ifdef OSCode
  64. #define BanditBase            0xf2000000
  65. #define BoardReg            0xF301a000
  66. #endif
  67.  
  68. #ifdef NativeCode
  69. #define BanditBase            0xf2000000
  70. #define BoardReg            0x9001a000
  71. #endif
  72.  
  73. /* PCI 0 device selections */
  74. #define BlueFish            (1 << 11)
  75. #define BlueFish1            (1 << 12)
  76. #define Jivi                (1 << 13)
  77. #define Gotham                (1 << 14)
  78.  
  79. /* PCI 1 device selections */
  80. #define BanditDev            (1 << 11)
  81. #define BanditDev1            (1 << 12)
  82. #define ESlotADev            (1 << 13)
  83. #define ESlotBDev            (1 << 14)
  84. #define ESlotCDev            (1 << 15)
  85. #define GrandCDev            (1 << 16)
  86. #define PCIOptDev            (1 << 17)
  87.  
  88. /* Configuation registers */
  89. #define DeviceID            0x00
  90. #define ConfigAdr            0x40
  91. #define AddressMask            0x48
  92. #define ModeSelect            0x58
  93.  
  94. #define PCI1Select            0x00000800
  95. #define Slot_A_Select        0x00002000
  96. #define Index_A                0x00
  97. #define Index_B                0x01
  98. #define Index_C                0x02
  99.  
  100. /* Configuration space register offsets */
  101. #define    PCI_VendorID        0x0000
  102. #define PCI_DeviceID        0x0002
  103. #define    PCI_Command            0x0004
  104. #define PCI_Status            0x0006
  105. #define    PCI_RevisionID        0x0008
  106. #define PCI_ClassCode        0x0009
  107. #define PCI_CacheLineSize    0x000c
  108. #define    PCI_LatencyTimer    0x000d
  109. #define    PCI_HeaderType        0x000e
  110. #define    PCI_BIST            0x000f
  111. #define    PCI_BaseAddress0    0x0010
  112. #define    PCI_BaseAddress1    0x0014
  113. #define    PCI_BaseAddress2    0x0018
  114. #define    PCI_BaseAddress3    0x001c
  115. #define    PCI_BaseAddress4    0x0020
  116. #define    PCI_BaseAddress5    0x0024
  117. #define    PCI_ExpansionROM    0x0030
  118. #define    PCI_InterruptLine    0x003c
  119. #define    PCI_InterruptPin    0x003d
  120. #define    PCI_Min_Gnt            0x003e
  121. #define    PCI_Max_Lat            0x003f
  122.  
  123. #define GrandCentral        0x90000000
  124. #define Slot_A                0xe0000000
  125. #define Slot_B                0xB0000000
  126. #define Slot_C                0xC0000000
  127. #define SlotUnderTest        ESlotBDev /* Slot B for now */
  128.  
  129. #define    PCI1Address            (BanditBase + 0x800000)
  130. #define    PCI1Data            (BanditBase + 0xc00000)
  131.  
  132. #define CPUID                0xf8000000
  133.  
  134. /**************************************** Utilities **************************************/
  135.  
  136.  
  137. UInt8 HackFlag;
  138. void BanditBug() {
  139.     UInt32 ByteBucket;
  140.     ByteBucket = PInt32 CPUID;
  141.     ByteBucket = PInt32 CPUID;
  142.     }
  143.  
  144. UInt32    ReverseLong(Value) UInt32 Value; {
  145.     UInt32 Temp;
  146.     Temp  = (( Value &        0x000000ff) << 24);
  147.     Temp += (((Value >> 8)  & 0x000000ff) << 16);
  148.     Temp += (((Value >> 16) & 0x000000ff) << 8);
  149.     Temp += (( Value >> 24) & 0x000000ff);
  150.     return(Temp);
  151.     }
  152.  
  153. UInt16    ReverseShort(Value) UInt16 Value; {
  154.     UInt16 Temp;
  155.     Temp = ((Value & 0x00ff) << 8);
  156.     Temp += ((Value >> 8) & 0x00ff);
  157.     return(Temp);
  158.     }
  159.  
  160. UInt8 Read8_Config(Address)
  161.     UInt32 Address;
  162.     {
  163.     UInt8 Data;
  164.     Int32Write(PCI1Address , ReverseLong(SlotUnderTest + Address));
  165.     BanditBug();
  166.     Data =Int8Read(PCI1Data);
  167.     BanditBug();
  168.     return(Data);
  169.     }
  170.  
  171. void Write8_Config(Address,Data)
  172.     UInt32 Address; UInt8 Data;
  173.     {
  174.     Int32Write(PCI1Address , ReverseLong(SlotUnderTest + Address));
  175.     BanditBug();
  176.     Int8Write(PCI1Data , Data);
  177.     BanditBug();
  178.     }
  179.  
  180. UInt16 Read16_Config(Address)
  181.     UInt32 Address;
  182.     {
  183.     UInt16 Data;
  184.     Int32Write(PCI1Address , ReverseLong(SlotUnderTest + Address));
  185.     BanditBug();
  186.     Data = ReverseShort(Int16Read(PCI1Data));
  187.     BanditBug();
  188.     return(Data);
  189.     }
  190.  
  191. void Write16_Config(Address,Data)
  192.     UInt32 Address; UInt16 Data;
  193.     {
  194.     BanditBug();
  195.     Int32Write(PCI1Address , ReverseLong(SlotUnderTest + Address));
  196.     BanditBug();
  197.     Int16Write(PCI1Data , ReverseShort(Data));
  198.     }
  199.  
  200. UInt32 Read32_Config(Address)
  201.     UInt32 Address;
  202.     {
  203.     UInt32 Data;
  204.     Int32Write(PCI1Address , ReverseLong(SlotUnderTest + Address));
  205.     BanditBug();
  206.     Data =ReverseLong(Int32Read(PCI1Data));
  207.     BanditBug();
  208.     return(Data);
  209.     }
  210.  
  211. void Write32_Config(Address,Data)
  212.     UInt32 Address,Data;
  213.     {
  214.     Int32Write(PCI1Address    , ReverseLong(SlotUnderTest + Address));
  215.     BanditBug();
  216.     Int32Write(PCI1Data        , ReverseLong(Data));
  217.     BanditBug();
  218.     }
  219.  
  220. void InitializeBandit() {
  221.     /* Set up bandit for 0x90000000, 0xA0000000, 0xB0000000, & 0xC0000000 */
  222.     Write32_Config(BanditDev    ,AddressMask+PCI1Select        ,0x1e0000c);
  223.  
  224.     /* Set Grand Central base address */
  225.     Write32_Config(GrandCDev    ,PCI_BaseAddress0    ,GrandCentral);
  226.     Write32_Config(GrandCDev    ,PCI_Command        ,0x00000016);
  227.     }
  228.  
  229. void InitializeSlot_A() {
  230.     Write32_Config(ESlotADev    ,PCI_Command        ,0x00000080);
  231.     Write32_Config(ESlotADev    ,PCI_BaseAddress0    ,Slot_A);
  232.     Write32_Config(ESlotADev    ,PCI_BaseAddress1    ,0x00009001);
  233.     Write32_Config(ESlotADev    ,PCI_Command        ,0x00000003);
  234.     }
  235.  
  236. void InitializeSlot_B() {
  237.     Write32_Config(ESlotBDev    ,PCI_Command        ,0x00000080);
  238.     Write32_Config(ESlotBDev    ,PCI_BaseAddress0    ,0x00000331);
  239. /*    Write32_Config(ESlotBDev    ,PCI_BaseAddress0    ,Slot_B); */
  240.     Write32_Config(ESlotBDev    ,PCI_Command        ,0x0000007);
  241.     }
  242.  
  243. void InitializeSlot_C() {
  244.     Write32_Config(ESlotCDev    ,PCI_BaseAddress0    ,Slot_C);
  245.     Write32_Config(ESlotCDev    ,PCI_Command        ,0x00000013);
  246.     }
  247.  
  248. /* Read presents bits for slot b only, Slot under test */
  249. UInt8 GetPresentsBits() {
  250.     return(((PInt8 BoardReg) >> 2) & 0x03);
  251.     }